<template>
    <div>
        <div class="block">
            <span class="demonstration">默认</span>
            <el-date-picker
                    v-model="value1"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd">
            </el-date-picker>
            <div>获取的日期是:{{arr}}</div>
            <button @click="getDays()">测试</button>
        </div>
    </div>
</template>

<script>
    export default {
        name: "block",
        data() {
            return {
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                value1: '',
                arr:'',//获取的时间
            };
        },
        methods: {
            test(){
                this
            },
            getDays() {
                const strDateStart = this.value1[0]
                const strDateEnd = this.value1[1]
                const strSeparator = "-";
                //日期分隔符   var oDate1;   var oDate2;
                let iDays;
                const oDate1 = strDateStart.split(strSeparator);
                const oDate2 = strDateEnd.split(strSeparator);
                const strDateS = new Date(oDate1[0], oDate1[1] - 1, oDate1[2]);
                const strDateE = new Date(oDate2[0], oDate2[1] - 1, oDate2[2]);
                this.arr = parseInt(Math.abs(strDateS - strDateE) / 1000 / 60 / 60 / 24)
                //把相差的毫秒数转换为天数
            }
        }
    }
</script>

<style scoped>

</style>
